home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / Basic Classes / Z Headers / ZMenuBar.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-15  |  6.2 KB  |  227 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp        -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZMenuBar.h            -- the menubar manager object
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21.  
  22. #pragma once
  23.  
  24. #ifndef __ZMENUBAR__
  25. #define    __ZMENUBAR__
  26.  
  27. #include    "ZComrade.h"
  28.  
  29. #include    <Menus.h>
  30.  
  31. class    ZArray;
  32.  
  33. // structure for storing info about a menu command
  34.  
  35. typedef struct
  36. {
  37.     long        theCmd;            // item's command
  38.     short        menuID;            // menu ID
  39.     short        itemID;            // item index
  40.     short         cmdFlags;        // associated command flags
  41.     short        subMenuID;        // if parent of submenu, menu we "own".
  42.     MenuHandle    macMenu;        // actual handle of menu that owns this command
  43. }
  44. MenuCmd;
  45.  
  46. // dimming options for entire menus:
  47.  
  48. enum
  49. {
  50.     neverDim = 0,
  51.     dimCommands = 1,
  52.     dimParentItems = 2,
  53.     dimOthers = 4,
  54.     dimAll = 8,
  55.     dimTitle = 32
  56. };
  57.  
  58. typedef unsigned char DimmingOptions;
  59.  
  60.  
  61. // structure for storing info about a whole menu:
  62.  
  63. typedef struct
  64. {
  65.     short            menuID;            // menu ID of the menu
  66.     short            mIndex;            // index into original MBAR resource
  67.     MenuHandle        macMenu;        // handle to the menu
  68.     DimmingOptions    mDimming;        // dimming flags
  69.     Boolean            mIsResource;    // TRUE if menu is a resource
  70. }
  71. MenuInfRec;
  72.  
  73. #if PRAGMA_ALIGN_SUPPORTED
  74. #pragma options align=mac68k
  75. #endif
  76.  
  77. // structure of CMNU resource:
  78.  
  79. typedef struct
  80. {
  81.     short            menuID;
  82.     long            fill1;
  83.     short            procID;
  84.     short            fill2;
  85.     unsigned long    flags;
  86.     char            mTitle;
  87. }
  88. CMNUResource, *CMNUResPtr, **CMNUResHdl;
  89.  
  90. // the items in the menu follow after the title, given the length of the title as
  91. // a number of bytes to skip forward. Each entry consists of the command item text
  92. // followed immediately by four bytes, <icon>, <key equiv>, <mark char>, <style>, 
  93. // followed by command ID (long), followed by next item.
  94.  
  95. typedef struct
  96. {
  97.     unsigned char    iconID;
  98.     unsigned char    keyEqu;
  99.     unsigned char    markChar;
  100.     unsigned char    iStyle;
  101. }
  102. CMNUEntry, *CMNUEntryPtr;
  103.  
  104. #if PRAGMA_ALIGN_SUPPORTED
  105. #pragma options align=reset
  106. #endif
  107.  
  108. // cmd flags
  109.  
  110. enum
  111. {
  112.     nothingSpecial = 0,
  113.     disableCmdsOnly = 1,
  114.     disableAll = 2,
  115.     disableParentItems = 4,
  116.     isPrimaryMenu = 8,
  117.     autoUnCheck = 16,
  118.     menuIsResource = 32
  119. };
  120.  
  121. // special commands
  122.  
  123. enum
  124. {
  125.     noCommand = 0,
  126.     parentCmd = 127
  127. };
  128.  
  129. // constants for AppendStdItems
  130.  
  131. enum
  132. {
  133.     appendDANames = 0,
  134.     appendFontNames
  135. };
  136.  
  137.  
  138. // menubar manager class
  139.  
  140. class    ZMenuBar : public ZComrade
  141. {
  142. protected:
  143.     short        mBarID;                // res ID of original MBAR resource
  144.     short        mbCount;            // number of items in main bar at top level
  145.     short        miSeed;                // index counter
  146.     short        mHelpOffset;        // count of items in help menu before we added any
  147.     short**        mBarH;                // Handle to menubar data during construction
  148.     ZArray*        theMenuCmds;        // array of MenuCmd structs used to map commands
  149.     ZArray*        theMenus;            // array of MenuInfRec structs for menu behaviours
  150.     char        menuCheckChar;        // character used for checking a menu item
  151.     short        wmMenuID;            // ID of windows menu
  152.  
  153. public:
  154.     
  155.     ZMenuBar( const short barID ) : ZComrade() { mBarID = barID; };
  156.     virtual ~ZMenuBar();
  157.     
  158.     virtual void        InitMenuBar();
  159.     
  160.     virtual void        UpdateMenuBar() { DrawMenuBar(); };
  161.     virtual void        ClickMenuBar( const Point mousePt );
  162.     virtual void        DispatchCommand( const long mSelect );
  163.     virtual void        DimMenus();
  164.     
  165.     virtual void        EnableCommand( const long cmd );
  166.     virtual void        EnableCommand( const short menuID, const short itemID );
  167.     virtual void        DisableCommand( const long cmd );
  168.     virtual void        DisableCommand( const short menuID, const short itemID );
  169.     
  170.     virtual void        CheckCommand( const long cmd, const Boolean checkOnOff );
  171.     virtual void        CheckCommand( const short menuID, const short itemID, const Boolean checkOnOff );
  172.     virtual void        CheckCommand( const short menuID, Str255 itemString, const Boolean checkOnOff );
  173.     
  174.     virtual void        SetCommandText( const long cmd, Str255 aText );
  175.     virtual void        SetCommandText( const short menuID, const short itemID, Str255 aText );
  176.     virtual void        SetCommandText( const long cmd, const short strListID, const short strIndex );
  177.     virtual void        SetCommandText( const short menuID, const short itemID, const short strListID, const short strIndex );
  178.     
  179.     virtual void        SetTitleHilite( const short menuID, const Boolean state );
  180.     virtual void        SetMenuDimming( const short menuID, const DimmingOptions dimOpts );
  181.     
  182.     virtual void        AppendMenuToBar( const short menuID );
  183.     virtual void        RemoveMenuFromBar( const short menuID );
  184.     virtual void        AppendStdItems( const short menuID, const short iType = appendDANames );
  185.     virtual MenuHandle    FindMenuID( const short menuID );
  186.     
  187.     virtual short        AppendHelpItem( Str255 itemText );    
  188.     
  189. // automatic "windows" menu handling:
  190.  
  191.     virtual void        NominateWindowsMenu( const short menuID );    
  192.     
  193. protected:
  194.     
  195.     virtual void        LoadMenus( const Boolean autoInstall = TRUE );
  196.     
  197.     virtual void        LoadMenu( const short menuID, Boolean isHMenu = FALSE, Boolean autoInstall = TRUE );
  198.     virtual void        LoadCMNUMenu( const short menuID, Boolean isHMenu = FALSE, Boolean autoInstall = TRUE );
  199.     virtual void        UnloadMenu( MenuHandle mH );
  200.     virtual void        PredimMenu( MenuHandle theMenu );
  201.     virtual void        ParseMenuItem( Str255 iText, long* aCmd ); 
  202.     
  203.     virtual void        FindMCmd( const long mSelect, MenuCmd* aCmd );
  204.     virtual void        FindCommand( const long cmd, short* menuID, short* itemID );
  205.  
  206.     virtual long        TrackMenuBar( const Point mouse );
  207.     virtual void        FindMenuInfo( const short menuID, MenuInfRec* mRec );    
  208. };
  209.  
  210.  
  211. // this object handles a menubar. By default, it calls the mac menu manager to work with the
  212. // global menubar at the top of the main monitor, but it can be subclassed to implement other
  213. // sorts of menubar, for example a mini-menubar in a window (this is left as an exercise!).
  214. // This loads menus and parses the items into a list of command IDs. When the menu item is
  215. // chosen, the associated command is looked up. This is then generally passed up the command
  216. // chain in force at the time.
  217.  
  218. // commands are associated initially with menu items using a #character, so your TCL resources
  219. // etc. can be used directly with this. e.g. "Open File...#12345" will result in the menu item
  220. // "Open File..." and the command number 12345. This will also use CMNU resources (a la MacApp)
  221. // if it can't find a MENU resource. Thus you get the best of both worlds!
  222.  
  223.  
  224. extern    ZMenuBar*    gMenuBar;
  225.  
  226.  
  227. #endif